package com.wty.shop.common;

import com.wty.shop.util.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author wangtengyu
 * @Create 2018-02-06-14:59
 */
@Component
@Slf4j
public class RedissonManager {

    private static String redis1Ip= PropertiesUtil.getProperty("redis1.ip");
    private static Integer redis1Port=Integer.parseInt(PropertiesUtil.getProperty("redis1.port"));

    private Config config=new Config();
    private Redisson redisson=null;

    @PostConstruct
    private void init(){

        try {
            config.useSingleServer().setAddress(new StringBuilder().append(redis1Ip).append(":").append(redis1Port).toString());
            redisson=(Redisson)Redisson.create(config);
            log.info("初始化Redisson结束");
        } catch (Exception e) {
            log.info("初始化Redisson失败");
        }
    }

    public Redisson getRedisson(){
        return redisson;
    }
}
